
return {
    beforePreProcess: function (content, url) {
        //beforePreProcess 页面初始化之前，可在此进行模版修改 or 定义新的参数
       
    },
    preprocess: function(content, url, next) {
        var self = this;
        this.context = $$.parseUrlQuery(url) || {},
        this.context.isHidePrice = Array.isArray(cb.rest.appContext.hidePrice) && 0 < cb.rest.appContext.hidePrice.length,
        cb.rest.getJSON({
            url: cb.router.HTTP_PRODUCT_LOADALLPROMOTIONSNEW,
            params: {},
            success: async function(data) {
                200 == data.code && (data.data.entirePromotion = self.tool.entireDeal.call(self, data.data.entirePromotion),
                data.data.selectFreePromotion = self.tool.selectFreeDeal.call(self, data.data.selectFreePromotion),
                await self.tool.format.call(self, data.data.productPromotion, data.data.entirePromotion, data.data.combinationPromotion, data.data.selectFreePromotion),
                data = Template7.compile(content)(self.context),
                next(data))
            },
            error: function(err) {
                myApp.toast(err.message, "error").show(!0)
            }
        })
    },
    beforePageInit: function (page) {
        var self = this
        self.tool.format= async function(data, entireArr, combinationArr, selectFreeObj) {
            var self = this;
            let editPrice = function(val, type) {
                let obj = {
                customer: cb.rest.appContext.context.agentId,
                deliveryMethod: '自提',
                receiveAddress: '',
                productDetail: [],
                }
                if(type == 0) {
                    val.forEach(element => {
                        let product = {
                            productCode: element.code,
                            productId: element.id,
                            org: element.saleOrgId,
                            priceQty: 1,
                            productUnitId: element.mainUnit.id,
                            currency: '1655486829428736015',
                            stockId: ''
                        }
                        obj.productDetail.push(product)
                    });
                } else if(type == 1) {
                    val.forEach(element => {
                        let product = {
                            productCode: element.product.code,
                            productId: element.product.id,
                            org: element.product.saleOrgId,
                            priceQty: 1,
                            productUnitId: element.product.mainUnit.id,
                            currency: '1655486829428736015',
                            stockId: ''
                        }
                        obj.productDetail.push(product)
                    });
                }
                return new Promise((resolve, reject) => {
                    cb.rest.postCross({
                        url: "https://saas.hlhs-bip.com/iuap-api-gateway/ajxbewdh/AcquisitionPrice/GetPriceAndFreight/pricing/acquisitionPrice?appKey=a4dc65b0fbab4f68a56e8054999a2ab3",
                        params: obj,
                        type:'post',
                        success: (res) => {
                            resolve(res.data)
                        },
                        error: function(errRes) {
                            console.log('errRes', errRes);
                        }
                    })
                })
            }
            return this.context.promotionGroups = [],
            this.context.isShowNav = data.length || 1 < entireArr.length || combinationArr.length,
            await Promise.all(Array.isArray(data) && data.map(async function(item) {
                let list = []
                if(item.products.length != 0){
                    list = await editPrice(item.products,0)
                }
                item.isProductPromotion = !0,
                Array.isArray(item.products) && item.products.length && (item.idkey = cb.utils.getGUID(),
                item.countTimeStr = self.tool.countTime.call(self, item.endDate),
                item.maxPreferentialNum && (item.notUsedPreferentialNum = cb.utils.FloatCalc.sub(item.maxPreferentialNum, item.usedPreferentialNum || 0)),
                item.products.forEach(function(product) {
                    product && (product.isHidePrice = self.context.isHidePrice,
                    product.salePrice = product.isHidePrice ? "***" : list[product.id].price || cb.FunctionOptions && cb.FunctionOptions.PRODUCTPRICESHOW,
                    0 < product.name.indexOf("®") && (product.name = product.name.replace(/®/g, "<sup>®</sup>")),
                    product.isShowPrice = cb.FunctionOptions && !cb.FunctionOptions.PRODUCTNOTSHOWPRICE)
                }),
                item.countTimeStr) && self.context.promotionGroups.push(item)
            })),
            await Promise.all(Array.isArray(combinationArr) && combinationArr.map(async function(item) {
                let list = []
                if(item.promotionProes.length != 0) {
                    list = await editPrice(item.promotionProes,1)
                }
                item.isCombination = !0,
                item.promotionName = item.name,
                item.endDate = item.promotion.endDate,
                item.countTimeStr = self.tool.countTime.call(self, item.endDate),
                item.maxPreferentialNum && (item.notUsedPreferentialNum = cb.utils.FloatCalc.sub(item.maxPreferentialNum, item.usedPreferentialNum || 0)),
                Array.isArray(item.promotionProes) && item.promotionProes.length && (item.idkey = cb.utils.getGUID(),
                item.promotionProes.forEach(function(product) {
                    // product.product.salePrice
                    product && product.product && (product.inventoryDisplay = product.product.inventoryDisplay,
                    product.imgUrl = product.product.imgUrl,
                    product.isHidePrice = self.context.isHidePrice,
                    product.product.salePrice = product.isHidePrice ? "***" : list[product.product.id].price || cb.FunctionOptions && cb.FunctionOptions.PRODUCTPRICESHOW,
                    0 < product.product.name.indexOf("®") && (product.product.name = product.product.name.replace(/®/g, "<sup>®</sup>")),
                    product.isShowPrice = cb.FunctionOptions && !cb.FunctionOptions.PRODUCTNOTSHOWPRICE)
                }),
                item.countTimeStr) && self.context.promotionGroups.push(item)
            })),
            selectFreeObj && (selectFreeObj.products.map(function(product) {
                product.mainPackageProduct || (product.mainPackageProduct = {}),
                product.mainPackageProduct && (product.mainPackageProduct.isHidePrice = self.context.isHidePrice,
                product.mainPackageProduct.salePrice = product.mainPackageProduct.isHidePrice ? "***" : product.salePrice || cb.FunctionOptions && cb.FunctionOptions.PRODUCTPRICESHOW,
                0 < product.mainPackageProduct.name.indexOf("®") && (product.mainPackageProduct.name = product.mainPackageProduct.name.replace(/®/g, "<sup>®</sup>")),
                product.mainPackageProduct.isShowPrice = cb.FunctionOptions && !cb.FunctionOptions.PRODUCTNOTSHOWPRICE)
            }),
            self.context.promotionGroups.push(selectFreeObj)),
            Array.isArray(entireArr) && entireArr.length && entireArr.forEach(function(v) {
                v.idkey = cb.utils.getGUID(),
                v.countTimeStr = self.tool.countTime.call(self, v.endDate),
                v.maxPreferentialNum && (v.notUsedPreferentialNum = cb.utils.FloatCalc.sub(v.maxPreferentialNum, v.usedPreferentialNum || 0)),
                v.countTimeStr && self.context.promotionGroups.push(v)
            }),
            this.context
        }
    },   
    afterPageInit: function (page) {
        // 该事件时  Dom已ready 但已执行当前页面固有逻辑
        console.log('lexus');
    },
    beforePageBack: function (page) {
        // 页面回退之前
    },
    afterPageBack: function (page) {
        // 页面回退之后
    },
};